<?php
include "include/config.inc.php";

if(!isset($_SESSION['s_activId']))
{
  header('location:index.php');
}
else
{
  $today = date("d-m-Y");
  $m=0;
  
  //Edit loanId
  $loanDetailId = $_REQUEST['loanDetailId'];
  $editLoan     = "SELECT grossWeight, less, purity, fine, rate, goldValue, landValue, propartyValue, constructionValue, 
                             value, itemImage, monthlyInterest, monthlyInterestRs, loanDate, lastInterestReceiveDate, endDate, 
                             itemlocation.itemlocationName, account.accountName, account.partyCode, account.address, account.mobile,
                             account.photo, account.otherInfo
                     FROM loan
                     JOIN itemlocation ON itemlocation.itemlocationId = loan.itemlocationId
                     JOIN account ON account.accountId = loan.accountId
                    WHERE loanId = ".$loanDetailId;
  $editLoanRes  = mysql_query($editLoan) or die("Error...".mysql_error());
  $editLoanRow  = mysql_fetch_array($editLoanRes);
  
  $transArray = array();
  $i          = 0;
  $paymentSelectionQry = "SELECT transdetail.crAmount,transdetail.amount1,transdetail.amountNarration,account.accountName
                            FROM transmaster
                            LEFT JOIN transdetail ON transdetail.transMasterId = transmaster.transMasterId
                            RIGHT JOIN account ON account.accountId = transdetail.crAccountId
                           WHERE transmaster.loanId = ".$loanDetailId;
  $paymentSelectionQryRes  = mysql_query($paymentSelectionQry) or die("Error...".mysql_error());
  while($transRow  = mysql_fetch_array($paymentSelectionQryRes))
  {
  	if($transRow['accountName'] != 'Interest Income')
  	{
	  	$transArray[$i]['accountName']     = $transRow['accountName']; 
	  	$transArray[$i]['amountNarration'] = $transRow['amountNarration']; 
	  	$transArray[$i]['amount1']         = $transRow['amount1']; 
	  	$transArray[$i]['crAmount']        = $transRow['crAmount']; 
	  	$i++;
	  }
  }
}

include("bottom.php");
//////fetch the party Name Over
$smarty->assign('editLoanRow',$editLoanRow);  
$smarty->assign('transArray',$transArray);  
$smarty->assign("today",$today);
$smarty->display('loanEdit.tpl');  
?>